<?php
class CommentController extends BaseController{
    public function index($id){
        header('Location: /WadOS/index/index');
    }

    public function edit($m_id){
        header('Location: /WadOS/index/index');
    }


    public function save($m_id){
        $curuser = UserMapper::getCurrentUser();
        if('' != $curuser->getId()){
            $com = new CommentModel();
            if(isset($_POST['text'])){

                $com->setText($_POST['text']);
                $com->setDate(date('Y-m-d h:m:s'));
                $com->setUserid($_POST['user_id']);
                $com->setMessageid($_POST['msg_id']);
                $com->save();
                
               header('Location: /WadOS/message/index/' . $_POST['msg_id']);
            }
        }else{
            header('Location: /WadOS/index/index');
        }
    }

    public  function delete(){
        $curuser = UserMapper::getCurrentUser();
        if('' != $curuser->getId()){
            if(isset($_GET['id'])){
                $com = new CommentModel();
                $com->find($_GET['id']);
                $com->delete();

                echo '<script>history.go(-1)</script>';
            }
        }else{
            header('Location: /WadOS/index/index');
        }
    }
}
?>
